// manager/pages/merchantmemberdesc/index.js
import { request } from '../../../utils/request';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 是否字典
        ynList: [],
        // 性别字典
        sexList: [],
        // 职位字典
        posList: [],
        // 业务需求字典
        // busiList: [],
        openList: [],
        memberTag: [],
        merchantId: "",
        memberId: "",
        memberDeatil: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        this.setData({
            merchantId: options.merchantId,
            memberId: options.memberId
        })
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.getMerchantPartInfo();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 获取是否、性别、职位、业务需求字典
     */
    getDictionaryInfo() {
        request({
            url: "/commonApi/getDictionaryInfo",
            method: "GET",
            data: {
				dictType: "common_yes_no"
			}
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    ynList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "cif_sex"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    sexList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_merchant_position"
                }
            })
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    posList: res.data
                })
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_personal_business_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                // this.setData({
                //     busiList: res.data
                // })
                this.getOpenList(res.data);
            }
            return request({
                url: "/commonApi/getDictionaryInfo",
                method: "GET",
                data: {
                    dictType: "ecard_personal_tag"
                }
            })
        }).then(res => {
            if(res.code == 0){
                // this.setData({
                //     memberTag: res.data
                // })
                this.getMemberTag(res.data);
            }
        }).catch(error => {
            // console.log(error)
        })
    },

    /**
     * 修改信息
     */
    editForm(e){
        wx.navigateTo({
          url: `/manager/pages/addmerchantmember/index?merchantId=${this.data.merchantId}&memberId=${this.data.memberId}`,
        })
    },
    // 成员信息
    getMerchantPartInfo(){
        request({
            url: "/merchantMarketing/getMerchantPartInfo",
            reqRSAENCRY: true, // 参数是否加密
            resRSADECRY: true, // 返回值是否解密
            data: {
                id: this.data.memberId
            }
        }).then(res => {
            if(res.code == 0){
                this.setData({
                    memberDeatil: res.data
                })
                this.getDictionaryInfo();
            }
        }).catch(error => {
            // console.log(error)
        })
    },
    // 获取业务标签
    getOpenList(list){
        let openList = [];
        let barr = this.data.memberDeatil.businessDemand?this.data.memberDeatil.businessDemand.split(","):[];
        list.forEach(item => {
            if(barr.indexOf(item.dictValue)!=-1){
                openList.push(item)
            }
        })
        this.setData({
            openList
        })
    },
    // 获取成员标签
    getMemberTag(list){
        let memberTag = [];
        let barr = this.data.memberDeatil.memberLabel?this.data.memberDeatil.memberLabel.split(","):[];
        list.forEach(item => {
            if(barr.indexOf(item.dictValue)!=-1){
                memberTag.push(item)
            }
        })
        this.setData({
            memberTag
        })
    },
})